/*
* @Author: hpp
* @Date:   2018-12-05 16:00:01
* @Last Modified by:   hpp
* @Last Modified time: 2018-12-05 18:28:20
*/

/**
 * 消息弹出层
 * @param  {String} msg  内容
 * @param  {String} type success、error、warning、info
 */
function alertMsg(msg = '',type="success",flag = true,subMsg = '2 秒后页面即将刷新~')
{
	toastr.options = {
	  "closeButton": false,
	  "debug": false,
	  "progressBar": true,
	  "preventDuplicates": false,
	  "positionClass": "toast-top-center",
	  "onclick": null,
	  "showDuration": "400",
	  "hideDuration": "1000",
	  // "timeOut": "7000",
	  "extendedTimeOut": "1000",
	  "showEasing": "swing",
	  "hideEasing": "linear",
	  "showMethod": "fadeIn",
	  "hideMethod": "fadeOut"
	}
	let len = msg.length;
	let title = flag ? subMsg : '';
	if (len <= 10 && len > 0) {
        toastr.options.timeOut = "1800";
    } else if (len <= 20) {
        toastr.options.timeOut = "2800";
    } else if (len <= 30) {
        toastr.options.timeOut = "3800";
    } else if (len > 30) {
        toastr.options.timeOut = "4800";
    }
    if (type=='success') {
    	toastr.success(title,msg);
    }else if(type=='info'){
    	toastr.info(title,msg);
    }else if(type == 'warning'){
    	toastr.warning(title,msg);
    }else if(type == 'error'){
    	toastr.error(title,msg);
    }
    if (flag) {
    	setTimeout( () => {
    		window.location.reload();
    	},2000);
    }
}